package com.syn.synold4s.control;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.core.content.ContextCompat;

import com.gaoyi.basemodule.baseControl.BaseView;
import com.gaoyi.basemodule.baseUtil.DateFormatUtil;
import com.syn.synold4s.R;
import com.syn.synold4s.databinding.SafetyTrainingViewBinding;

import java.util.Date;

public class SafetyTrainingView extends BaseView<SafetyTrainingViewBinding> {

    public SafetyTrainingView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void initView(TypedArray ta) {
        // 底部文本
        String name = ta.getString(R.styleable.SafetyTrainingView_safety_training_name);
        String fraction = ta.getString(R.styleable.SafetyTrainingView_safety_training_fraction);
        String time = ta.getString(R.styleable.SafetyTrainingView_safety_training_time);
        String curriculum = ta.getString(R.styleable.SafetyTrainingView_safety_training_curriculum);
        setName(name);
        setCurriculum(curriculum);
        mBinding.tvTrainingTime.setText(time);
        mBinding.tvTrainingFraction.setText(fraction);
    }

    public void setName(String name) {
        mBinding.tvTrainingName.setText(name == null ? "" : name);
    }

    public void setTime(String date) {
        mBinding.tvTrainingTime.setText(date != null?date:"");
    }

    public void setCurriculum(String curriculum) {
        mBinding.tvTrainingCurriculum.setText(curriculum == null ? "" : curriculum);
    }

    public void setFraction(String fraction, int status) {
        mBinding.tvTrainingFraction.setText(fraction == null ? "---" : fraction);
        if (fraction != null && !fraction.isEmpty()) {
            mBinding.tvTrainingFraction.setTextColor(ContextCompat.getColor(mContext, R.color.green));
        }else {
            mBinding.tvTrainingFraction.setTextColor(ContextCompat.getColor(mContext, R.color.color_text));
        }
    }

    @Override
    protected SafetyTrainingViewBinding getViewBinding() {
        return SafetyTrainingViewBinding.inflate(LayoutInflater.from(mContext));
    }

    @Override
    protected int[] getAttrs() {
        return R.styleable.SafetyTrainingView;
    }
}
